<template>
  <view class="container" v-if="isLoaded">
    <!-- logo -->
    <u-avatar :src="storeInfo.FAdvUrl" shape="circle" size="80"></u-avatar>
    <!-- storeName -->
    <view style="margin: 30px 0; font-size: 18px"
      >已绑定店铺<text
        style="font-weight: bold; font-size: 20px; color: #fe0203"
        >{{ storeInfo.StoreName }}</text
      ></view
    >
    <!-- <view></view> -->
    <!-- btn bind store -->
  </view>
</template>

<script>
import { reqPost } from "../../common/http.request";
import { useUser } from "../../store/useUser";
import { uSetStorageSync, uSwitchTab, uToast } from "../../utils/uniUtils";

export default {
  data() {
    return {
      isLoaded: false,
      storeInfo: null,
    };
  },
  async onLoad({ scene }) {
    if (scene != undefined && scene.length > 0) {
      console.log("scene", scene);
      try {
        await this.getPageData(scene);
        this.isLoaded = true;
      } catch (error) {
        console.log("error", error);
      }
    } else {
      console.log("scene", "undefined");
      uToast("二维码错误~", "error");
      uSwitchTab("/pages/tab_bar/index");
    }
  },
  methods: {
    async getPageData(scene) {
      const { Data } = await reqPost("GetStoreInfoByScene", {
        scene,
      });
      
      this.storeInfo = Data;
      uSetStorageSync("m_store_info", Data);
      uSetStorageSync("hasBindStore", true);
      uSetStorageSync("hasLogin", false);
      await useUser().appLogin();
    },
  },
};
</script>

<style lang="scss" scoped>
.container {
  height: calc(100vh-150px);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 150px;
}
</style>
